var t = getApp(), i = require("../../A4730AC3A71FB5DFC21562C4223CA4D1.js"), a = require("../../0BACB9C3A71FB5DF6DCAD1C4BE4CA4D1.js");

Page({
    data: {
        winWidth: t.globalData.windowWidth,
        curSize: "",
        curSrc: "",
        addressResult: [],
        province: "",
        city: "",
        area: "",
        name: "",
        productId: null,
        address: "",
        left: [],
        right: [],
        list: [],
        isShow: !1
    },
    onLoad: function(i) {
        var a = this, e = t.globalData.isLogin;
        this.setData({
            isLogin: e
        }, function() {
            e || a.login();
        }), this.getPictureList();
    },
    onShow: function() {
        null !== a._cb && (this.setData({
            isLogining: !1
        }), a._cb = null);
    },
    login: function() {
        var i = this;
        t.globalData.isLogin || this.data.isLogining || this.setData({
            isLogining: !0
        }, function() {
            a.login(function(t) {
                i.setData({
                    isLogining: !1,
                    isLogin: !0
                });
            });
        });
    },
    onShareAppMessage: function() {},
    getPictureList: function() {
        var t = this;
        i.get("/v1/ali/product").then(function(i) {
            1001 === i.data.code && t.setData({
                list: i.data.response.data
            }, function() {
                t.formatPictureList();
            });
        });
    },
    formatPictureList: function() {
        for (var t = this.data.list, i = 0, a = 0, e = [], s = [], n = 0; n < t.length; n++) {
            var o = t[n], r = o.product_printimg.width, d = o.product_printimg.height, c = JSON.parse(JSON.stringify(o));
            c.product_printimg.width = 327, c.product_printimg.height = 327 * d / r, i <= a ? (i += (c.product_printimg.height || 0) + 102, 
            e.push(c)) : (a += (c.product_printimg.height || 0) + 102, s.push(c));
        }
        this.setData({
            left: e,
            right: s
        });
    },
    changeSize: function(t) {
        this.setData({
            curSize: t.currentTarget.dataset.size
        });
    },
    handleAddress: function(t) {
        var i = t.detail.value;
        i.length && this.setData({
            addressResult: i,
            province: i[0] || "",
            city: i[1] || "",
            area: i[2] || ""
        });
    },
    handleInput: function(t) {
        var i = {};
        i[t.currentTarget.dataset.type] = t.detail.value, this.setData(i);
    },
    submit: function() {
        var a = this;
        if (t.globalData.isLogin) {
            if (!this.data.isLoading) {
                var e = this.data.productId;
                if (e) {
                    var s = this.data.curSize;
                    if (s) {
                        var n = this.data.name.trim();
                        if (n) {
                            var o = this.data.telephone.trim();
                            if (o) if (/^1(3|4|5|6|7|8|9)\d{9}$/.test(o)) {
                                var r = this.data, d = r.province, c = r.city, h = r.area;
                                if (d && c) {
                                    h || (h = c);
                                    var u = this.data.address.trim();
                                    u ? (this.setData({
                                        isLoading: !0
                                    }), wx.showLoading(), i.post("/v1/ali/apiorder", {
                                        product_id: e,
                                        size: s,
                                        name: n,
                                        telephone: o,
                                        province: d,
                                        city: c,
                                        area: h,
                                        address: u,
                                        user_id: t.globalData.user.user_id
                                    }).then(function(t) {
                                        if (wx.hideLoading(), a.setData({
                                            isLoading: !1
                                        }), 1001 === t.data.code) {
                                            var i = t.data.response.data;
                                            wx.navigateTo({
                                                url: "/pages/pay/pay?from=activity&orderId=" + i.order_id + "&price=" + i.order_total_paid / 100
                                            });
                                        }
                                    }).catch(function() {
                                        wx.hideLoading(), a.setData({
                                            isLoading: !1
                                        });
                                    })) : myToast("请输入详细地址");
                                } else wx.showToast({
                                    title: "请选择所在地区",
                                    icon: "none"
                                });
                            } else wx.showToast({
                                title: "请输入正确的手机号码",
                                icon: "none"
                            }); else wx.showToast({
                                title: "请输入手机号码",
                                icon: "none"
                            });
                        } else wx.showToast({
                            title: "请输入收货人",
                            icon: "none"
                        });
                    } else wx.showToast({
                        title: "请选择衣服尺寸",
                        icon: "none"
                    });
                } else wx.showToast({
                    title: "请选择作品图案",
                    icon: "none"
                });
            }
        } else this.login();
    },
    previewImg: function(t) {
        this.setData({
            curSrc: t.currentTarget.dataset.src,
            isShow: !0
        });
    },
    hidePreviewBox: function() {
        this.setData({
            isShow: !1
        });
    },
    handleProduct: function(t) {
        this.setData({
            productId: 1 * t.currentTarget.dataset.id
        });
    }
});